<?php include('login_header.php');?>
<div class="container">
	<form name="login_form" method="post" class="form-signin">
		<h2 class="form-signin-heading">ADMIN</h2>
		<input name="id" type="text" class="input-block-level" placeholder="ID"> 
		<input name="password" type="password" class="input-block-level" placeholder="Password">
		<button class="btn btn-large btn-primary" type="submit">Sign in</button>
	</form>
</div>
<script src="<?=JS_DIR?>/jquery-1.8.3.min.js"></script>
<script src="<?=JS_DIR?>/respond.min.js"></script>
<script src="<?=BS_DIR?>/admin/js/bootstrap.min.js"></script>
<script src="<?=JS_DIR?>/jquery.validate.min.js"></script>
<script>
$(function(){
	$("input[name='id']").focus();
	$("form[name='login_form']").validate({
		rules: {
			id : {
				required : true
			},
			password : {
				required : true
			}
   		},
		messages: {
			id : {
				required : "<div class='alert alert-error'>INPUT YOUR ID!</div>"
			},
			password : {
				required : "<div class='alert alert-error'>INPUT YOUR PASSWORD!</div>"
			}
		},
		submitHandler: function(){
			$.ajax({
				type: 'post',
				url: "<?=base_url('admin/login_action')?>",
				data: { 
					id : $("input[name='id']").val(),
					password : $("input[name='password']").val()
				},
				success: function(data){
					if(data.result) location.href = "<?=base_url('admin/pageview')?>";
					else {
						alert('ID OR PASSWORD IS INCORRECT!');
						$("form[name='login_form']")[0].reset();
						$("input[name='id']").focus();
					}
				},
				error: function(jqXHR, textStatus, errorThrown){
					alert( errorThrown );
				}
			});
		}
	});
 });
</script>
<?php include('login_footer.php');?>